package com.example.jbmsuppliers.sinopec.activity;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;

import com.example.jbmsuppliers.R;
import com.example.jbmsuppliers.sinopec.net.NetWork;
import com.example.jbmsuppliers.sinopec.utlis.ExitAppUtlis;
import com.jbm.jbmsupplier.util.ICtrl;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

import static com.jbm.jbmsupplier.util.abstracts.SendMessageInterfase.gSocket;

/**
 * Created by 家帮忙 on 2017/3/1.
 */

public class MySexChang extends ActivityUse {
    @InjectView(R.id.radionan)
    RadioButton radionan;
    @InjectView(R.id.redionv)
    RadioButton redionv;
    private final int MODISEX = 0001;
    int i;
    @InjectView(R.id.goback_ps_nisex)
    Button gobackPsNisex;
    @InjectView(R.id.buttbaocunsex)
    Button buttbaocunsex;
    @InjectView(R.id.texui)
    TextView texui;
    private TextView modiname;

    @Override
    protected int setContentView1() {
        return R.layout.lz_changsex;
    }

    @Override
    protected void initView() {
        ExitAppUtlis.getInstance().addActivity(this);
        ButterKnife.inject(this);
        texui.setText("修改性别");
    }
//
//    @Override
//    protected void onCreate(@Nullable Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        ExitAppUtlis.getInstance().addActivity(this);
//        setContentView(R.layout.lz_changsex);
//        ButterKnife.inject(this);
//
//    }

    @OnClick({R.id.radionan, R.id.redionv, R.id.goback_ps_nisex, R.id.buttbaocunsex})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.radionan:
                radionan.setChecked(true);
                redionv.setChecked(false);
                i = 1;
                break;
            case R.id.redionv:
                redionv.setChecked(true);
                radionan.setChecked(false);
                i = 2;
                break;
            case R.id.goback_ps_nisex:
                finish();
                break;
            case R.id.buttbaocunsex:
                if (!redionv.isChecked() && !radionan.isChecked()) {
                    hint("修改信息不能为空");
                    return;
                }
                NetWork netWork = new NetWork(handler);
                netWork.setModiSex(gSocket.login_id, "", i, MODISEX);
                break;
        }
    }

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MODISEX: {
                    ICtrl modimessage = (ICtrl) msg.obj;
                    if (modimessage.back) {
//                        new Intent().putExtra("sex",i);
                        setResult(RESULT_OK, new Intent().putExtra("sex", i));
                        finish();
                    } else {
                        hint(modimessage.errorinfo);
                    }
                    break;
                }

            }

            super.handleMessage(msg);
        }
    };



}
